package com.niit.utils;

import java.util.List;

public class Page<T> {

	private List<T> list;// 产生的记录集
	private int pageCount;// 总页数
	private int total;// 总记录数
	private int pageSize = 10;// 页面大小
	private int curPage;// 当前页面
	private int startIndex;// 开始记录
	@SuppressWarnings("unused")
	private int endIndex;// 结束记录
	private int startPage;// 开始页码
	private int endPage;// 结束页码
	private String url;// 处理分页的servlet

	public Page(int total, int curPage) {
		this.total = total;
		pageCount = (total - 1) / pageSize + 1;
		this.curPage = curPage;
		startIndex = (curPage - 1) * pageSize;
		if (pageCount < pageSize) {
			startPage = 1;
			endPage = pageCount;
		} else {
			this.startPage = this.curPage - 4;
			this.endPage = this.curPage + 5;

			if (this.startPage < 1) {
				this.startPage = 1;
				this.endPage = pageSize;
			}
			if (this.endPage > this.pageCount) {
				this.endPage = this.pageCount;
				this.startPage = this.pageCount - pageSize + 1;
			}
		}
	}

	public List<T> getList() {
		return list;
	}

	public void setList(List<T> list) {
		this.list = list;
	}

	public int getPageCount() {
		return pageCount;
	}

	public void setPageCount(int pageCount) {
		this.pageCount = pageCount;
	}

	public int getTotal() {
		return total;
	}

	public void setTotal(int total) {
		this.total = total;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public int getCurPage() {
		return curPage;
	}

	public void setCurPage(int curPage) {
		this.curPage = curPage;
	}

	public int getStartIndex() {
		return startIndex;
	}

	public void setStartIndex(int startIndex) {
		this.startIndex = startIndex;
	}

	public int getStartPage() {
		return startPage;
	}

	public void setStartPage(int startPage) {
		this.startPage = startPage;
	}

	public int getEndPage() {
		return endPage;
	}

	public void setEndPage(int endPage) {
		this.endPage = endPage;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}
	
	public int getEndIndex() {
		return startIndex + pageSize;
	}

}
